package com.tanhua.server.controller;

import com.tanhua.domain.vo.CommentVo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.server.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Classname CommentController
 * @Description TODO 评论列表web
 * @Date 2021/3/14 17:10
 * @Created by gan
 */
@RestController
@RequestMapping("/comments")
public class CommentController {
    @Autowired
    private CommentService commentService;

    //评论列表
    @GetMapping
    public ResponseEntity findPage(String movementId, @RequestParam(defaultValue = "1")
                                   int page,@RequestParam(defaultValue = "10")int pagesize){
        page=page>0?page:1;
        PageResult<CommentVo> result=commentService.findPage(movementId,page,pagesize);
        return ResponseEntity.ok(result);

    }

    //发表评论
    @PostMapping
    public ResponseEntity add(@RequestBody Map<String,String> paramMap){
       long count= commentService.add(paramMap);
        return ResponseEntity.ok(count);
    }

    //评论点赞
    @GetMapping("/{id}/like")
    public ResponseEntity<Long>like(@PathVariable("id")String commentId){
        Long total=commentService.likeComment(commentId);
        return ResponseEntity.ok(total);
    }

    //评论取消点赞
    @GetMapping("/{id}/dislike")
    public ResponseEntity<Long> unlike(@PathVariable("id") String commentId){
        Long total = commentService.unlikeComment(commentId);
        return ResponseEntity.ok(total);
    }
}
